<template>
    <div>
        <ul class="nav nav-tabs" role="tablist">
            <li role="presentation" class="active"><a href="#type" role="tab" data-toggle="tab">物料分类</a></li>
            <li role="presentation"><a href="#manage" role="tab" data-toggle="tab">物料管理</a></li>
        </ul>
        <div class="tab-content">
            <div class="tab-pane active" id="type" role="tabpanel">
                <div class="operation">
                        <!--<a class="btn btn-theme">添加物料</a>-->
                        <a class="btn btn-theme" @click="showAddChildModal">添加子级</a>
                        <a class="btn btn-theme" @click="showAddBrothModal">添加同级</a>
                        <!--<a class="btn btn-theme" >编辑物料</a>-->
                        <a class="btn btn-theme" @click="deleteType">删除</a>
                </div>
                <div style="border:2px solid #d2d6de" id="material_content">
                    <ul id="material_content_ul" style="font-size:12px;">

                    </ul>
                </div>
                 <div class="modal fade" id="material_add_kind_modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
                    <div class="modal-dialog" role="document">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="exampleModalLabel">添加物料</h4>
                            </div>
                            <div class="modal-body">
                                <form>
                                    <div class="form-group">
                                        <label class="control-label">物料名称</label>
                                        <input id="material_add_kind_name" type="text" class="form-control">
                                    </div>
                                </form>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                                <button type="button" class="btn btn-primary" id="material_add_kind_submit" @click="addType">提交</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="tab-pane" role="tabpanel" id="manage">
                <div v-show="!showDetail">
                <div class="operation">
                        <a class="btn btn-theme" @click="addMaterial">添加物料</a>
                        <a class="btn btn-theme" @click="modifyMaterial">编辑物料</a>
                        <a class="btn btn-theme" @click="showDeleteTip">删除物料</a>
                </div>
                <table class="table"></table>
                </div>

                <div v-show="showDetail">
                                        <div class="container-fluid col-md-12">
                                            <h4>基本信息</h4>
                                            <div class="row" style="border:2px solid #d2d6de ; padding:10px;border-radius:5px;background-color:#fbfbfb">
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_itemno" class="control-label">物料编码</label>
                                                    <input type="text" class="form-control input-sm" name="materialname" id="material_add_itemno">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_cname" class="control-label">中文名称</label>
                                                    <input type="text" class="form-control input-sm" name="cname" id="material_add_cname">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_ename" class="control-label">英文名称</label>
                                                    <input type="text" class="form-control input-sm" name="ename" id="material_add_ename">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_model" class="control-label">型号</label>
                                                    <input type="text" class="form-control input-sm " name="model" id="material_add_model">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_color" class="control-label">颜色</label>
                                                    <input type="text" class="form-control input-sm" name="color" id="material_add_color">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_chartnumber" class="control-label">图号</label>
                                                    <input type="text" class="form-control input-sm" name="chartnumber" id="material_add_chartnumber">
                                                </div>

                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_abc" class="control-label">ABC分类码</label>
                                                    <select name="abc" class="form-control input-sm" id="material_add_abc">
                                                <option value="1">1</option>
                                                <option value="2">2</option>
                                            </select>
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_status" class="control-label">状态</label>
                                                    <input type="text" class="form-control input-sm" name="status" id="material_add_status">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_cost" class="control-label">成本</label>
                                                    <input type="text" class="form-control input-sm" name="cost" id="material_add_cost">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_desc9" class="control-label">是否固定资产</label>
                                                    <select type="text" class="form-control input-sm" name="desc9" id="material_add_desc9">
                                                        <option value="固定资产">固定资产</option>
                                                        <option value="非固定资产">非固定资产</option>
                                                        <!--<option value="固定资产">固定资产</option>-->
                                                    </select>

                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_desc7" class="control-label">单位</label>
                                                    <select type="text" class="form-control input-sm" name="desc7" id="material_add_desc7"></select>
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_desc8" class="control-label">物料类型</label>
                                                    <select type="text" class="form-control input-sm" name="desc8" id="material_add_desc8">
                                                       <option value="办公设施">办公设施</option>
                                                       <option value="常规配件">常规配件</option>
                                                       <option value="工程配件">工程配件</option>
                                                       <option value="表单耗材">表单耗材</option>
                                                       <option value="外修">外修</option>
                                                       <option value="低值易耗品">低值易耗品</option>
                                                       <option value="标签耗材">标签耗材</option>
                                                       <option value="保养配件">保养配件</option>
                                                       <option value="保养工具">保养工具</option>
                                                       <option value="易耗品">易耗品</option>
                                                       <option value="办公耗材">办公耗材</option>
                                                       <option value="IT设施">IT设施</option>
                                                       <option value="外修配件">外修配件</option>
                                                       <option value="特殊配件">特殊配件</option>
                                                       <option value="工具配件">工具配件</option>
                                                       <option value="工具易耗品">工具易耗品</option>
                                                       <option value="维修配件">维修配件</option>
                                                       <option value="IT服务">IT服务</option>
                                                       <option value="业务推广">业务推广</option>
                                                       <option value="其他">其他</option>
                                                    </select>

                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_desc10" class="control-label">标准件/非标准件</label>
                                                    <select type="text" class="form-control input-sm" name="desc10" id="material_add_desc10">
                                                        <option value="标准件">标准件</option>
                                                    <option value="非标准件">非标准件</option>
                                                    </select>

                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label class="checkbox-inline" style="margin-top:30px;">
                                            <input type="checkbox" id="material_add_lock" value='true'>是否锁定
                                            </label>
                                                </div>
                                            </div>
                                        </div>


                                        <div class="container-fluid col-md-12">
                                            <h4>库存信息</h4>
                                            <div class="row" style="border:2px solid #d2d6de ; padding:10px;border-radius:5px;background-color:#fbfbfb">
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_defaultwh" class="control-label">默认仓库</label>
                                                    <input type="text" class="form-control input-sm" name="defaultwh" id="material_add_defaultwh">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_defaultct" class="control-label">默认库位</label>
                                                    <input type="text" class="form-control input-sm" name="defaultct" id="material_add_defaultct">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_maxwh" class="control-label">最大库存</label>
                                                    <input type="text" class="form-control input-sm" name="maxwh" id="material_add_maxwh">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_secuitywh" class="control-label">安全库存</label>
                                                    <input type="text" class="form-control input-sm" name="secuitywh" id="material_add_secuitywh">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_minwh" class="control-label">最小库存</label>
                                                    <input type="text" class="form-control input-sm" name="minwh" id="material_add_minwh">
                                                </div>
                                            </div>

                                        </div>

                                        <div class="container-fluid col-md-12">
                                            <h4>尺寸信息</h4>
                                            <div class="row" style="border:2px solid #d2d6de ; padding:10px;border-radius:5px; background-color:#fbfbfb">
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_long" class="control-label">长度</label>
                                                    <input type="text" class="form-control input-sm" name="long" id="material_add_long">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_width" class="control-label">宽度</label>
                                                    <input type="text" class="form-control input-sm" name="width" id="material_add_width">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_height" class="control-label">高度</label>
                                                    <input type="text" class="form-control input-sm" name="height" id="material_add_height">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_defaulengthltunitid" class="control-label">默认长度单位</label>
                                                    <select name="defaulengthltunitid" class="form-control input-sm" id="material_add_defaulengthltunitid">

                                            </select>

                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_netweight" class="control-label">净重</label>
                                                    <input type="text" class="form-control input-sm" name="netweight" id="material_add_netweight">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_grossweight" class="control-label">毛重</label>
                                                    <input type="text" class="form-control input-sm" name="grossweight" id="material_add_grossweight">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_defaultweightunitid" class="control-label">默认重量单位</label>
                                                    <select name="defaultweightunitid" class="form-control input-sm" id="material_add_defaultweightunitid">
                                                
                                            </select>

                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_volume" class="control-label">体积</label>
                                                    <input type="text" class="form-control input-sm" name="volume" id="material_add_volume">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_defaultvolumeunitid" class="control-label">体积单位</label>
                                                    <select name="defaultvolumeunitid" class="form-control input-sm" id="material_add_defaultvolumeunitid">
                                                
                                            </select>
                                                </div>

                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_thickness" class="control-label">厚度</label>
                                                    <input type="text" class="form-control input-sm" name="thickness" id="material_add_thickness">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_thicknessunit" class="control-label">厚度单位</label>
                                                    <select name="thicknessunit" class="form-control input-sm" id="material_add_thicknessunit">
                                                
                                            </select>
                                                </div>
                                            </div>

                                        </div>
               <div class="container-fluid col-md-12">
                                            <h4>备注与描述</h4>
                                            <div class="row" style="border:2px solid #d2d6de ; padding:10px;border-radius:5px; background-color:#fbfbfb">
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_notes" class="control-label">备注</label>
                                                    <input type="text" class="form-control input-sm" name="notes" id="material_add_notes">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_desc" class="control-label">描述</label>
                                                    <input type="text" class="form-control input-sm" name="desc" id="material_add_desc">
                                                </div>

                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_desc1" class="control-label">描述1</label>
                                                    <input type="text" class="form-control input-sm" name="desc1" id="material_add_desc1">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_desc2" class="control-label">描述2</label>
                                                    <input type="text" class="form-control input-sm" name="desc2" id="material_add_desc2">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_desc3" class="control-label">描述3</label>
                                                    <input type="text" class="form-control input-sm" name="desc3" id="material_add_desc3">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_desc4" class="control-label">描述4</label>
                                                    <input type="text" class="form-control input-sm" name="desc4" id="material_add_desc4">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_desc5" class="control-label">描述5</label>
                                                    <input type="text" class="form-control input-sm" name="desc5" id="material_add_desc5">
                                                </div>
                                                <div class="form-group1 col-md-3">
                                                    <label for="material_add_desc6" class="control-label">描述6</label>
                                                    <input type="text" class="form-control input-sm" name="desc6" id="material_add_desc6">
                                                </div>
                                            </div>
                 </div>
                 <div style="text-align: right">
                      <a class="btn btn-theme btn-sm" v-show="ifNew" @click="save">保存</a>
                      <a class="btn btn-theme btn-sm" v-show="!ifNew" @click="submit">提交</a>
                      <a class="btn btn-theme btn-sm" @click="changeShowDetail">返回</a>
                 </div>
             </div>
                
               
            </div>
        </div>
        <div id="deleteTip" class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                    <h4 class="modal-title">删除警告</h4>
                </div>
                <div class="modal-body">
                    <p>确定要删除第{{currentId}}号物料？</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary" @click="deleteMaterial">确定</button>
                </div>
                </div><!-- /.modal-content -->
            </div><!-- /.modal-dialog -->
            </div><!-- /.modal -->
    </div>
</template>
<script>
    export default {
        data() {
            return {
                tabledata: '',
                showDetail: false,
                ifNew: true,
                currentId: '',
                currentTypeid: ''
            }
        },
        methods: {
            getTable() {
                var _this = this
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/item/FetchallList',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid
                    },
                    dataType: 'json',
                    crossDomain: true,
                    async: false,
                    error(request) {
                        _this.$store.commit('showModal','连接错误')
                    },
                    success(res) {
                        _this.tabledata = res.Table2
                    }
                });
                $('.table').bootstrapTable('destroy')
                $('.table').bootstrapTable({
                    columns: [{
                        checkbox: true,
                    }, {
                        field: 'fidno',
                        title: '物料号',
                        halign: 'center'
                    }, {
                        field: 'fitemno',
                        title: '物料编码',
                        halign: 'center'
                    }, {
                        field: 'fcgn',
                        title: '中文名称',
                        halign: 'center'
                    }, {
                        field: 'fmodel',
                        title: '型号',
                        halign: 'center'
                    }, {
                        field: 'fdesc9',
                        title: '是否固定资产',
                        halign: 'center'
                    }, {
                        field: 'fdesc8',
                        title: '类型',
                        halign: 'center'
                    }],
                    data: this.tabledata,
                    pagination: true,
                    // paginationLoop: true,
                    onlyInfoPagination: false,
                    striped: true,
                    sortName: 'fidno',
                    sortOrder: 'desc',
                    sidePagination: 'client',
                    pageNumber: 1,
                    pageSize: 10,
                    pageList: [10, 25, 50, 100],
                    smartDisplay: true,
                    search: true,
                    selectItemName: 'material',
                    searchOnEnterKey: false,
                    strictSearch: false,
                    showHeader: true,
                    //showFooter: true,

                    //detailView: true,
                    clickToSelect: true,
                    singleSelect: true,
                    //checkboxHeader: true,
                    //radio: true,
                    checkbox: true,
                    //clickToSelect: true,
                })
            },
            changeShowDetail() {
                this.showDetail = !this.showDetail
            },
            addMaterial() {
                this.ifNew = true
                this.showDetail = !this.showDetail
                var _this = this
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/item/getMaxNo',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                        'teamid': localStorage.activeteamid
                    },
                    dataType: 'json',
                    crossDomain: true,
                    async: false,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误');
                    },
                    success: function(retdata) {
                        var res = parseInt(retdata.Table2[0].Column1.slice(4)) + 1;
                        res = 'WLBM' + res;
                        $('#material_add_itemno').val(res)
                    }
                });
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/itemtype/fetchalltype',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                        'teamid': localStorage.activeteamid
                    },
                    dataType: 'json',
                    crossDomain: true,
                    async: false,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误');
                    },
                    success: function(retdata) {
                        var html = ''
                        for (var i = 0; i < retdata.Table2.length; i++) {
                            html += '<option value="' + retdata.Table2[i].fdname + '">' + retdata.Table2[i].fdname + '</option>'
                        }
                        $('#material_add_desc8').html(html)
                    }
                });
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/unit/fetchalllist',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                    },
                    dataType: 'json',
                    crossDomain: true,
                    async: false,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误');
                    },
                    success: function(retdata) {
                        var info_unit = retdata;
                        for (var i = 0; i < info_unit.Table2.length; i++) {

                            $('#material_add_defaultweightunitid,#material_add_defaulengthltunitid,#material_add_thicknessunit,#material_add_defaultvolumeunitid,#material_add_desc7').append('<option value="' + info_unit.Table2[i].fcname + '">' + info_unit.Table2[i].fcname + '</option>');
                        }
                    }
                });
            },
            save() {
                var _this = this
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/item/Add',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                        'teamid': localStorage.activeteamid,
                        'fitemno': $('#material_add_itemno').val(),
                        "flock": $('#material_add_lock:checked').val(),
                        "fcgn": $('#material_add_cname').val(),
                        "fegn": $('#material_add_ename').val(),
                        "fmodel": $('#material_add_model').val(),
                        "fcolor": $('#material_add_color').val(),
                        "ftid": $('#material_add_ftid').val(),
                        "fstatus": $('#material_add_status').val(),
                        "fcost": $('#material_add_cost').val(),
                        "fmaxwh": $('#material_add_maxwh').val(),
                        "fsecuitywh": $('#material_add_secuitywh').val(),
                        "fminwh": $('#material_add_minwh').val(),
                        "fdesc": $('#material_add_desc').val(),
                        "fnotes": $('#material_add_notes').val(),
                        "fdefaulengthltunitid": $('#material_add_defaulengthltunitid').val(),
                        "fheight": $('#material_add_height').val(),
                        "fwidth": $('#material_add_width').val(),
                        "flong": $('#material_add_long').val(),
                        "fnetweight": $('#material_add_netweight').val(),
                        "fgrossweight": $('#material_add_grossweight').val(),
                        "fdefaultweightunitid": $('#material_add_defaultweightunitid').val(),
                        "fdefaultwh": $('#material_add_defaultwh').val(),
                        "fdefaultlct": $('#material_add_defaultct').val(),
                        "fvolume": $('#material_add_volume').val(),
                        "fdefaultvolumeunitid": $('#material_add_defaultvolumeunitid').val(),
                        "fchartnumber": $('#material_add_chartnumber').val(),
                        "fabc": $('#material_add_abc').val(),
                        "fthickness": $('#material_add_thickness').val(),
                        "fthicknessunit": $('#material_add_thicknessunit').val(),
                        "fdesc1": $('#material_add_desc1').val(),
                        "fdesc2": $('#material_add_desc2').val(),
                        "fdesc3": $('#material_add_desc3').val(),
                        "fdesc4": $('#material_add_desc4').val(),
                        "fdesc5": $('#material_add_desc5').val(),
                        "fdesc6": $('#material_add_desc6').val(),
                        "fdesc7": $('#material_add_desc7').val(),
                        "fdesc8": $('#material_add_desc8').val(),
                        "fdesc9": $('#material_add_desc9').val(),
                        "fdesc10": $('#material_add_desc10').val(),
                        "fsource": $('#material_add_source').val(),
                    },
                    async: true,
                    dataType: 'json',
                    crossDomain: true,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误')
                    },
                    success: function(retdata) {
                        if (retdata.Table1[0].message == "物料编码已存在，请更换") {
                            _this.$store.commit('showModal','物料编码已存在，请更换')
                        } else {
                            _this.changeShowDetail()
                        }
                    }
                });
            },
            modifyMaterial() {
                var _this = this
                this.ifNew = false
                this.showDetail = true
                this.currentId = $('.selected').children().eq(1).text()
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/unit/fetchalllist',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                    },
                    dataType: 'json',
                    crossDomain: true,
                    async: false,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误');
                    },
                    success: function(retdata) {
                        var info_unit = retdata;
                        for (var i = 0; i < info_unit.Table2.length; i++) {
                            $('#material_add_defaultweightunitid,#material_add_defaulengthltunitid,#material_add_thicknessunit,#material_add_defaultvolumeunitid,#material_add_desc7').append('<option value="' + info_unit.Table2[i].fcname + '">' + info_unit.Table2[i].fcname + '</option>');
                        }
                    }
                });
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/itemtype/fetchalltype',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                        'teamid': localStorage.activeteamid
                    },
                    dataType: 'json',
                    crossDomain: true,
                    async: false,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误');
                    },
                    success: function(retdata) {
                        var html = ''
                        for (var i = 0; i < retdata.Table2.length; i++) {
                            html += '<option value="' + retdata.Table2[i].fdname + '">' + retdata.Table2[i].fdname + '</option>'
                        }
                        $('#material_add_desc8').html(html)
                    }
                });
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/item/fetchlistbyid',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                        'fidno': $('.selected').children().eq(1).text()
                    },
                    dataType: 'json',
                    crossDomain: true,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误');
                    },
                    success: function(retdata) {
                        $('#material_add_itemno').val(retdata.Table2[0].fitemno)
                        $('#material_add_cname').val(retdata.Table2[0].fcgn);
                        $('#material_add_ename').val(retdata.Table2[0].fegn);
                        $('#material_add_model').val(retdata.Table2[0].fmodel);
                        $('#material_add_color').val(retdata.Table2[0].fcolor);
                        $('#material_add_lock').prop('checked', retdata.Table2[0].flock);
                        $('#material_add_ftid').val(retdata.Table2[0].ftid);
                        $('#material_add_status').val(retdata.Table2[0].fstatus);
                        $('#material_add_cost').val(retdata.Table2[0].fcost);
                        $('#material_add_maxwh').val(retdata.Table2[0].fmaxwh);
                        $('#material_add_secuitywh').val(retdata.Table2[0].fsecuitywh);
                        $('#material_add_minwh').val(retdata.Table2[0].fminwh);
                        $('#material_add_desc').val(retdata.Table2[0].fdesc);
                        $('#material_add_notes').val(retdata.Table2[0].fnotes);
                        $('#material_add_defaulengthltunitid').val(retdata.Table2[0].fdefaulengthltunitid);
                        $('#material_add_height').val(retdata.Table2[0].fheight);
                        $('#material_add_width').val(retdata.Table2[0].fwidth);
                        $('#material_add_long').val(retdata.Table2[0].flong);
                        $('#material_add_netweight').val(retdata.Table2[0].fnetweight);
                        $('#material_add_grossweight').val(retdata.Table2[0].fgrossweight);
                        $('#material_add_defaultweightunitid').val(retdata.Table2[0].fdefaultweightunitid);
                        $('#material_add_defaultwh').val(retdata.Table2[0].fdefaultwh);
                        $('#material_add_defaultct').val(retdata.Table2[0].fdefaultlct);
                        $('#material_add_volume').val(retdata.Table2[0].fvolume);
                        $('#material_add_defaultvolumeunitid').val(retdata.Table2[0].fdefaultvolumeunitid);
                        $('#material_add_chartnumber').val(retdata.Table2[0].fchartnumber);
                        $('#material_add_abc').val(retdata.Table2[0].fabc);
                        $('#material_add_thickness').val(retdata.Table2[0].fthickness);
                        $('#material_add_thicknessunit').val(retdata.Table2[0].fthicknessunit);
                        $('#material_add_desc1').val(retdata.Table2[0].fdesc1);
                        $('#material_add_desc2').val(retdata.Table2[0].fdesc2);
                        $('#material_add_desc3').val(retdata.Table2[0].fdesc3);
                        $('#material_add_desc4').val(retdata.Table2[0].fdesc4);
                        $('#material_add_desc5').val(retdata.Table2[0].fdesc5);
                        $('#material_add_desc6').val(retdata.Table2[0].fdesc6);
                        $('#material_add_desc7').val(retdata.Table2[0].fdesc7);
                        $('#material_add_desc8').val(retdata.Table2[0].fdesc8);
                        $('#material_add_desc9').val(retdata.Table2[0].fdesc9);
                        $('#material_add_desc10').val(retdata.Table2[0].fdesc10);
                        $('#material_add_source').val(retdata.Table2[0].fsource);
                    }
                });
            },
            submit() {
                var _this = this
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/item/Update',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                        'teamid': localStorage.activeteamid,
                        'fidno': _this.currentId,
                        'fitemno': $('#material_add_itemno').val(),
                        "flock": $('#material_add_lock:checked').val(),
                        "fcgn": $('#material_add_cname').val(),
                        "fegn": $('#material_add_ename').val(),
                        "fmodel": $('#material_add_model').val(),
                        "fcolor": $('#material_add_color').val(),
                        "ftid": $('#material_add_ftid').val(),
                        "fstatus": $('#material_add_status').val(),
                        "fcost": $('#material_add_cost').val(),
                        "fmaxwh": $('#material_add_maxwh').val(),
                        "fsecuitywh": $('#material_add_secuitywh').val(),
                        "fminwh": $('#material_add_minwh').val(),
                        "fdesc": $('#material_add_desc').val(),
                        "fnotes": $('#material_add_notes').val(),
                        "fdefaulengthltunitid": $('#material_add_defaulengthltunitid').val(),
                        "fheight": $('#material_add_height').val(),
                        "fwidth": $('#material_add_width').val(),
                        "flong": $('#material_add_long').val(),
                        "fnetweight": $('#material_add_netweight').val(),
                        "fgrossweight": $('#material_add_grossweight').val(),
                        "fdefaultweightunitid": $('#material_add_defaultweightunitid').val(),
                        "fdefaultwh": $('#material_add_defaultwh').val(),
                        "fdefaultlct": $('#material_add_defaultct').val(),
                        "fvolume": $('#material_add_volume').val(),
                        "fdefaultvolumeunitid": $('#material_add_defaultvolumeunitid').val(),
                        "fchartnumber": $('#material_add_chartnumber').val(),
                        "fabc": $('#material_add_abc').val(),
                        "fthickness": $('#material_add_thickness').val(),
                        "fthicknessunit": $('#material_add_thicknessunit').val(),
                        "fdesc1": $('#material_add_desc1').val(),
                        "fdesc2": $('#material_add_desc2').val(),
                        "fdesc3": $('#material_add_desc3').val(),
                        "fdesc4": $('#material_add_desc4').val(),
                        "fdesc5": $('#material_add_desc5').val(),
                        "fdesc6": $('#material_add_desc6').val(),
                        "fdesc7": $('#material_add_desc7').val(),
                        "fdesc8": $('#material_add_desc8').val(),
                        "fdesc9": $('#material_add_desc9').val(),
                        "fdesc10": $('#material_add_desc10').val(),
                        "fsource": $('#material_add_source').val(),
                    },
                    crossDomain: true,
                    dataType: 'json',
                    async: 'true',
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误')
                    },
                    success: function(retdata) {
                        _this.showDetail = false
                        _this.getTable()
                    }
                });
            },
            showDeleteTip() {
                this.currentId = $('.selected').children().eq(1).text()
                $('#deleteTip').modal('show')
            },
            deleteMaterial() {
                var _this = this
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/item/delete',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                        'fidno': _this.currentId
                    },
                    dataType: 'json',
                    crossDomain: true,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误')
                    },
                    success: function() {
                        $('#deleteTip').modal('hide')
                        _this.getTable()
                    }
                });
            },
            getType() {
                var _this = this
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/itemtype/fetchalllist',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                        'teamid': localStorage.activeteamid,
                    },
                    dataType: 'json',
                    crossDomain: true,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误');
                    },
                    success: function(retdata) {
                        if (retdata.Table2[0].result == false) {
                            $('#material_add_child,#material_add_brother,#material_modify_kind,#material_drop_kind').hide();
                        } else {
                            $('#material_add_material').hide();
                            var j = 0;
                            parent = [];
                            var htmlcont = '';
                            for (var i = 0; i < retdata.Table2.length; i++) {
                                if (retdata.Table2[i].fdid == 0) {
                                    htmlcont += '<li id="' + retdata.Table2[i].fidno + '"><input type="radio" name="material">' + retdata.Table2[i].fdname + '<ul></ul></li>';

                                    parent[j] = retdata.Table2[i].fidno;
                                    j++;
                                }
                            }
                            $('#material_content_ul').html(htmlcont);
                            for (var i = 0; i < retdata.Table2.length; i++) {
                                for (var x = 0; x < j; x++) {
                                    if (retdata.Table2[i].fdid == parent[x]) {
                                        $('li').each(function() {
                                            if ($(this).attr('id') == parent[x]) {
                                                $(this).children('ul').append('<li id="' + retdata.Table2[i].fidno + '"><input type="radio" name="material">' + retdata.Table2[i].fdname + '<ul></ul></li>');
                                            }
                                        });
                                        parent[j++] = retdata.Table2[i].fidno;
                                    }
                                }
                            }
                        }
                    }
                });
            },
            showAddChildModal() {
                this.currentTypeid = $("input:radio[name='material']:checked").map(function(index, elem) {
                    return $(elem).parent().attr('id');
                }).get().join();
                if (this.currentTypeid == '') {
                    this.$store.commit('showModal','请先选择材料类目')
                } else {
                    $('#material_add_kind_modal').modal('show');
                }
            },
            showAddBrothModal() {
                this.currentTypeid = $("input:radio[name='material']:checked").map(function(index, elem) {
                    return $(elem).parent().parent().parent().attr('id');
                }).get();
                if (this.currentTypeid == '') {
                    this.$store.commit('showModal','请先选择材料类目')
                } else {
                    $('#material_add_kind_modal').modal('show');
                }
            },
            addType() {
                var _this = this
                $.ajax({
                    type: 'POST',
                    url: 'http://192.168.1.66:808/api/itemtype/add',
                    data: {
                        'token': localStorage.token,
                        'userid': localStorage.userid,
                        'fdid': _this.currentTypeid,
                        'fdname': $('#material_add_kind_name').val(),
                        'teamid': localStorage.activeteamid
                    },
                    dataType: 'json',
                    crossDomain: true,
                    error: function(request) {
                        _this.$store.commit('showModal','连接错误')
                    },
                    success: function(retdata) {
                        $('#material_add_kind_modal').modal('hide');
                        _this.getType()
                    }
                });
            },
            deleteType() {
                var _this = this
                this.currentTypeid = $("input:radio[name='material']:checked").map(function(index, elem) {
                    return $(elem).parent().children().children('li').eq(0).attr('id');
                }).get();
                if (this.currentTypeid == '') {
                    this.currentTypeid = $("input:radio[name='material']:checked").map(function(index, elem) {
                        return $(elem).parent().attr('id');
                    }).get();
                    $.ajax({
                        type: 'POST',
                        url: 'http://192.168.1.66:808/api/itemtype/delete',
                        data: {
                            'token': localStorage.token,
                            'userid': localStorage.userid,
                            'fidno': _this.currentTypeid,
                        },
                        //async:false,
                        dataType: 'json',
                        crossDomain: true,
                        error: function(request) {
                            _this.$store.commit('showModal','连接错误')
                        },
                        success: function(retdata) {
                            _this.getType()
                        }
                    });
                } else {
                    _this.$store.commit('showModal','该类目下面有子分类，不能删除！')
                }
            }
        },
        mounted() {
            this.getTable()
            this.getType()
        }
    }
</script>
<style>
    #material_content {
        clear: both;
        text-align: left
    }
    
    #material_content li {
        list-style: none
    }
</style>